import java.util.ArrayList;


public class Game {

	Board board;
	Boolean turnwhite;
	ArrayList<Coordinate> possibleMoves;
	int whitePieces;
	int blackPieces;
	
	public Game(){
		this.board = new Board();
		board.initiate();
		turnwhite = true;
		possibleMoves = board.getPossibleMoves((turnwhite)?1:2);
	}
	
	public Board getBoard(){
		return board;
	}
	
	public ArrayList<Coordinate> getPossibleMoves(){
		return possibleMoves;
	}
	
	public boolean getTurn(){
		return turnwhite;
	}
	
	public void randomTurn(){
		if (turnwhite){
			Coordinate co = board.getPossibleMoves(1).get(0);
			board.setPiece(co.x, co.y, 1);
			turnwhite = !turnwhite;
			possibleMoves = board.getPossibleMoves(2);
		}else{
			Coordinate co = board.getPossibleMoves(2).get(0);
			board.setPiece(co.x, co.y, 2);
			turnwhite = !turnwhite;
			possibleMoves = board.getPossibleMoves(1);
			updateCount();
		}
		
		
		
	}
	
	public void playerTurn(int x, int y){
		if (turnwhite){
			board.setPiece(x, y, 1);
			turnwhite = !turnwhite;
			possibleMoves = board.getPossibleMoves(2);
			updateCount();
			randomTurn();
		}
	}
	
	public void updateCount(){
		whitePieces=0;
		blackPieces=0;
		
		for (int i = 0; i < getBoard().getData().length; i++) {
			for (int j = 0; j < getBoard().getData().length; j++) {
				if (getBoard().getData()[j][i]==1)
					whitePieces +=1;
				if (getBoard().getData()[j][i]==2)
					blackPieces +=1;
			}
		}
	}
	
	public int getWhitePieces(){
	
		return whitePieces;
	}
	
	public int getBlackPieces(){
		return blackPieces;
	}
	
}
